package com.linux.huhx.thread2;

import java.sql.Time;
import java.util.Random;
import java.util.concurrent.TimeUnit;

public class MyThread extends Thread {
    volatile public static int count;
//    public static int count;
    private static void addCount() {
        System.out.println("add " + count);
        count += 10;
    }

    private static void descCount() {
        System.out.println("desc " + count);
        count -= 10;
    }

    private static void getCount() {
        System.out.println("count = " + count);
    }

    @Override
    public void run() {
        try {
            addCount();
            TimeUnit.MILLISECONDS.sleep(new Random().nextInt(9999));
            descCount();
            TimeUnit.MILLISECONDS.sleep(new Random().nextInt(9999));
            getCount();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
